package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: BrandServiceImpl
 * @Package: com.atguigu.spzx.manager.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/7 15:10
 */
@Service
@Transactional
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo<Brand> findBrandPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Brand> brandList = brandMapper.selectBrandPage();
        return new PageInfo<>(brandList);
    }

    @Override
    public void addBrand(Brand brand) {
        brandMapper.insertBrand(brand);
    }

    @Override
    @Transactional(readOnly = true)
    public Brand findBrandById(Long id) {
        return brandMapper.selectBrandById(id);
    }

    @Override
    public void changeBrandById(Brand brand) {
        brandMapper.updateBrandById(brand);
    }

    @Override
    public void removeBrandById(Long id) {
        brandMapper.deleteBrandById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Brand> findAllBrand() {
        return brandMapper.selectAllBrand();
    }
}
